package ${package.ServiceImpl};

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;

/**
 * @Author: ${author}
 * @Date: ${date}
 * @Description:
 **/
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

}
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
    <#-- 将mapper的name首字母小写 -->
    <#assign lowerMapperName = table.mapperName?substring(0,1)?lowerCase + table.mapperName?substring(1)>
    <#assign lowerEntityName = entity?substring(0,1)?lowerCase + entity?substring(1)>

    @Resource
    private ${table.mapperName} ${lowerMapperName};

    @Override
    public ${entity} get${entity}ById(Long id) {
        Preconditions.checkNotNull(id, "Id不能为空");
        return ${lowerMapperName}.select${entity}ById(id);
    }

    @Override
    public List<${entity}> list${entity}(${entity} bean) {
        return ${lowerMapperName}.select${entity}List(bean);
    }

    @Override
    public IPage<${entity}> list${entity}ByPage(Page<${entity}> page, ${entity} bean) {
        return ${lowerMapperName}.select${entity}ListByPage(page, bean);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public Integer add${entity}(${entity} bean) {
        return ${lowerMapperName}.insert${entity}(bean);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public Integer modify${entity}ById(${entity} bean) {
        Preconditions.checkNotNull(bean.getId(), "Id不能为空");
        return ${lowerMapperName}.update${entity}ById(bean);
    }

    @Override
    public Integer remove${entity}ById(Long id) {
        Preconditions.checkNotNull(id, "Id不能为空");
        return ${lowerMapperName}.delete${entity}ById(id);
    }

}
</#if>
